home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 52
/
Volume 52 - JOGO DISK .iso
/
Games
/
shopdrop.swf
/
scripts
/
__Packages
/
smashing
/
Point3D.as
< prev
next >
Wrap
Text File
|
2007-09-27
|
4KB
|
182 lines
class smashing.Point3D
{
function Point3D(x, y, z)
{
this.x = Number(x);
this.y = Number(y);
this.z = Number(z);
}
function get length()
{
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
}
function set length(newLength)
{
if(this.__get__length() != 0)
{
var _loc2_ = newLength / this.__get__length();
this.x *= _loc2_;
this.y *= _loc2_;
this.z *= _loc2_;
}
}
function get lengthSqu()
{
return this.x * this.x + this.y * this.y + this.z * this.z;
}
function copy()
{
return new smashing.Point3D(this.x,this.y,this.z);
}
function addPoint(p)
{
return new smashing.Point3D(p.x + this.x,p.y + this.y,p.z + this.z);
}
function subtractPoint(p)
{
return new smashing.Point3D(this.x - p.x,this.y - p.y,this.z - p.z);
}
function addScalar(n)
{
return new smashing.Point3D(this.x + n,this.y + n,this.z + n);
}
function subtractScalar(n)
{
return new smashing.Point3D(this.x - n,this.y - n,this.z - n);
}
function addPointMe(p)
{
this.x += p.x;
this.y += p.y;
this.z += p.z;
}
function subtractPointMe(p)
{
this.x -= p.x;
this.y -= p.y;
this.z -= p.z;
}
function addScalarMe(n)
{
this.x += n;
this.y += n;
this.z += n;
}
function subtractScalarMe(n)
{
this.x -= n;
this.y -= n;
this.z -= n;
}
function multiply(n)
{
var _loc2_ = this.copy();
_loc2_.x *= n;
_loc2_.y *= n;
_loc2_.z *= n;
return _loc2_;
}
function divide(n)
{
var _loc2_ = this.copy();
if(n == 0)
{
_loc2_.x = 0;
_loc2_.y = 0;
_loc2_.z = 0;
return undefined;
}
_loc2_.x /= n;
_loc2_.y /= n;
_loc2_.z /= n;
return _loc2_;
}
function multiplyMe(n)
{
this.x *= n;
this.y *= n;
this.z *= n;
}
function divideMe(n)
{
this.x /= n;
this.y /= n;
this.z /= n;
}
function dot(p)
{
return this.x * p.x + this.y * p.y + this.z * p.z;
}
function cross(p)
{
return new smashing.Point3D(this.y * p.z - this.z * p.y,this.z * p.x - this.x * p.z,this.x * p.y - this.y * p.x);
}
function pseudoCross()
{
return new smashing.Point3D(this.y,- this.x,this.z);
}
function normalize()
{
if(!this.x && !this.y && !this.z)
{
return undefined;
}
var _loc2_ = this.__get__length();
return new smashing.Point3D(this.x / _loc2_,this.y / _loc2_,this.z / _loc2_);
}
function normalizeMe()
{
if(!this.x && !this.y)
{
return undefined;
}
var _loc2_ = this.__get__length();
this.x /= _loc2_;
this.y /= _loc2_;
this.z /= _loc2_;
}
function reverse()
{
var _loc2_ = new smashing.Point3D(this.x * -1,this.y * -1,this.z * -1);
return _loc2_;
}
function reverseMe()
{
this.x *= -1;
this.y *= -1;
this.z *= -1;
}
function findCosine(vOther)
{
var _loc3_ = this.dot(vOther);
var _loc4_ = this.__get__length() * vOther.__get__length();
var _loc2_ = _loc3_ / _loc4_;
return _loc2_;
}
function equals(p)
{
if(this.x == p.x && this.y == p.y && this.z == p.z)
{
return true;
}
return false;
}
function zero()
{
this.x = 0;
this.y = 0;
this.z = 0;
}
function distSqu(p)
{
var _loc4_ = p.x - this.x;
var _loc3_ = p.y - this.y;
var _loc2_ = p.z - this.z;
return _loc4_ * _loc4_ + _loc3_ * _loc3_ + _loc2_ * _loc2_;
}
function toString()
{
return "Point3D (" + this.x + "," + this.y + "," + this.z + ")";
}
}